//
//  LGDeviceSendAdressView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/9.
//

#import "LGDeviceSendAdressView.h"

@interface LGDeviceSendAdressView()
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *adressLabel;
/**   */
@property (nonatomic , strong)UIButton *copyaBtn;

@end

@implementation LGDeviceSendAdressView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.titleBtn setTitle:@"收货地址" forState:UIControlStateNormal];
        [self.titleBtn setImage:[UIImage imageNamed:@"设备发货-收货地址"] forState:UIControlStateNormal];
        [self addSubview:self.nameLabel];
        [self addSubview:self.adressLabel];
        [self addSubview:self.copyaBtn];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(45));
            make.left.equalTo(self).offset(viewPix(12));
            make.right.equalTo(self).offset(-viewPix(12));
        }];
        [self.adressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(8));
            make.left.right.equalTo(self.nameLabel);
        }];
        [self.copyaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.equalTo(self).offset(-viewPix(12));
            make.width.equalTo(@(viewPix(88)));
            make.height.equalTo(@(viewPix(32)));
        }];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    if(dataDic.allKeys.count > 0){
        self.nameLabel.text = [NSString stringWithFormat:@"%@ %@",dataDic[@"consignee"],dataDic[@"mobile"]];
        self.adressLabel.text = [NSString stringWithFormat:@"%@ %@ %@ %@ %@",dataDic[@"province"],dataDic[@"city"],dataDic[@"region"],dataDic[@"sub_district"],dataDic[@"address_detail"]];
    }else{
        self.nameLabel.text = @"--";
        self.adressLabel.text = @"";
        self.copyaBtn.hidden = YES;
    }
}

-(void)copyAdressAction{
    UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
    pasteBoard.string = [NSString stringWithFormat:@"%@ %@",self.nameLabel.text,self.adressLabel.text];
    [TooltipView showMessage:@"复制成功" offset:0];
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)adressLabel{
    if(!_adressLabel){
        _adressLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _adressLabel;
}

-(UIButton *)copyaBtn{
    if(!_copyaBtn){
        _copyaBtn = [UIButton buttonWithTitle:@"复制地址" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#FFFFFF" selectColor:@"#FFFFFF"];
        _copyaBtn.backgroundColor = [UIColor colorWithString:@"#3291FF"];
        _copyaBtn.cornerRidus = viewPix(16);
        [_copyaBtn addTarget:self action:@selector(copyAdressAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _copyaBtn;
}

@end
